(function( $ ){
	var defaults = {
		limit_visible : 5,
		speed_hide_all : 800
	};
	var show_hide = 'show';
	var methods = {
		init:function(params) {
			
			//var options = $.extend({}, defaults, params);
			methods.main_tethod_all(defaults);
			methods.click_show_all();
			methods.click_hide_all(defaults);
		},
		main_tethod_all:function(options){
			$('.one_filter').each(function(){
				methods.logics(this);
			});
		},
		main_tethod_one:function(one_block){
				methods.logics(one_block);
		},
		logics:function(parent){
			var count_item = 0;
				var isset_active_element = false;
				var if_find_active = $(parent).find('.active').length ; 
				var bil_ili_nebil = false;
				$(parent).find('.one_item').each(function(){
					count_item++;
					if($(this).hasClass('active')){
						isset_active_element = true;
						bil_ili_nebil = true;
					}else
						isset_active_element = false;
					if(if_find_active && count_item > (defaults.limit_visible -1) && !bil_ili_nebil){
						$(this).hide();
					}
					if(if_find_active && count_item > defaults.limit_visible && bil_ili_nebil){
						$(this).hide();
					}
					if(!if_find_active && count_item > defaults.limit_visible){
						$(this).hide();
					}
					if(isset_active_element){
						$(this).show();
					}
				});
				if(count_item > (defaults.limit_visible+1)){
					methods.show_all($(parent).children('.filter_show_hide_all'));
				}
		},
		show_all:function(parent){
			$(parent).show();
			$(parent).find('.filter_show_all').show();
			$(parent).find('.filter_hide_all').hide();
		},
		hide_all:function(parent){
			$(parent).show();
			$(parent).find('.filter_hide_all').show();
			$(parent).find('.filter_show_all').hide();
		},
		click_show_all:function(){
			$('.filter_show_all').click(function(){
				$(this).parent('.filter_show_hide_all').siblings('.one_item').show();
				methods.hide_all($(this).parent('.filter_show_hide_all'));
			});
		},
		click_hide_all:function(options){
			$('.filter_hide_all').click(function(){
				methods.main_tethod_one($(this).parent('.filter_show_hide_all').parent('.one_filter'),defaults);
				$(this).parent('.filter_show_hide_all').parent('.one_filter').position();
				var top_parent = $(this).parent('.filter_show_hide_all').parent('.one_filter').position();
				$("html, body").animate({ scrollTop: top_parent.top}, defaults.speed_hide_all);
			});
		}
	};
	
	$.fn.FiltersEmployer = function(method){
		if ( methods[method] ) {
			return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
		} else if ( typeof method === 'object' || ! method ) {
			return methods.init.apply( this, arguments );
		} else {
			$.error( 'Метод "' +  method + '" не найден в плагине jQuery.PaymentsEmployer' );
		}
	};
})( jQuery );